/*
package cloud.xlh.filter;

import cloud.xlh.domin.vo.CommonRspVO;
import cloud.xlh.exceptionhandle.service.impl.BusinessExceptionEnum;
import cloud.xlh.infrastructure.utils.StringUtil;
import cloud.xlh.properties.IgnoreWhiteProperties;
import cloud.xlh.service.TokenService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

*/
/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/1/15 17:19
 * @ Description: 网关鉴权
 *//*

@Slf4j
@Component
public class AuthFilter implements GlobalFilter, Ordered {
    @Autowired
    private IgnoreWhiteProperties ignoreWhite;
    @Autowired
    private TokenService tokenService;
    @Value("${redirect-url}")
    private String redirectUrl;

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        String url = request.getURI().getPath();
        */
/**
         * 跳过不需要验证的路径
         * *//*

        if (StringUtil.matches(url, ignoreWhite.getWhites())) {
            return chain.filter(exchange);
        }
        */
/**
         * 判断是否携带token，没有携带则返回登陆界面，有就校验，通过就传递下个链路，没有则返回登陆界面
         * *//*

        String token = tokenService.getToken(request);
        if (StringUtil.isEmpty(token)) {
            */
/**
             * 重定向到登录页面
             * *//*

            ServerHttpResponse response = exchange.getResponse();
            response.setStatusCode(HttpStatus.SEE_OTHER);
            response.getHeaders().set(HttpHeaders.LOCATION, redirectUrl);
            return response.setComplete();
            //return setUnauthorizedResponse(exchange, "令牌不能为空");
        }
        */
/**
         * 校验token
         * *//*

        if (tokenService.checkToken(token)) {
            return chain.filter(exchange);
        } else {
            return setUnauthorizedResponse(exchange,
                    String.valueOf(BusinessExceptionEnum.TOKENINVALID.getCode()) ,
                    BusinessExceptionEnum.TOKENINVALID.getMessage());
        }
    }

    @Override
    public int getOrder() {
        return -400;
    }

    private Mono<Void> setUnauthorizedResponse(ServerWebExchange exchange, String retCode , String msg) {
        ServerHttpResponse response = exchange.getResponse();
        response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
        response.setStatusCode(HttpStatus.UNAUTHORIZED);

        log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());

        return response.writeWith(Mono.fromSupplier(() -> {
            DataBufferFactory bufferFactory = response.bufferFactory();
            return bufferFactory.wrap(JSON.toJSONBytes(new CommonRspVO<>().builder
                    .retCode(String.valueOf(retCode))
                    .retInfo(msg)
                    .build()));
        }));
    }
}
*/
